#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <softTone.h>
#include <pcf8591.h>
#include <wiringPi.h>
#include <python3.11/Python.h>

int main(){
    int timer1,dt_1,dt;
    // Py_Initialize();
    // PyObject * mos= PyImport_ImportModule("os");
    // PyObject * mtime= PyImport_ImportModule("time");
    // PyObject * mPILl= PyImport_ImportModule("PIL");
    // // PyObject * mFont= PyImport_ImportModule("PIL.ImageFont");
    // PyObject * lumaod = PyImport_ImportModule("luma.oled.device");
    // PyObject * lumaci = PyImport_ImportModule("luma.core.interface.serial");
    // PyObject * lumacr = PyImport_ImportModule("luma.core.render");
    // PyObject * func_i2c = PyObject_GetAttrString(lumaci,"i2c");
    // PyObject * func_canvas = PyObject_GetAttrString(lumacr,"canvas");
    // PyObject * func_ssd1306 = PyObject_GetAttrString(lumaod,"ssd1306");
    // PyObject * args_i2c = PyTuple_New(2);
    // // printf("aaa\n");
    // PyTuple_SetItem(args_i2c,0,Py_BuildValue("i",1));
    // PyTuple_SetItem(args_i2c,1,Py_BuildValue("i",0x3C));
    // PyObject * serial = PyObject_CallObject(func_i2c,args_i2c);
    // PyObject * args_ssd = PyTuple_New(3);
    // PyTuple_SetItem(args_ssd,0,serial);
    // PyTuple_SetItem(args_ssd,1,Py_BuildValue("i",128));
    // PyTuple_SetItem(args_ssd,2,Py_BuildValue("i",64));
    // // printf("aaa\n");
    // PyObject * device = PyObject_CallObject(func_ssd1306,args_ssd);
    // // printf("aaa\n");
    // // PyObject * args_canvas = PyTuple_New(1);
    // // printf("aaa\n");
    // // PyTuple_SetItem(args_canvas,0,device);
    // // printf("aaa\n");
    // PyObject * draw =PyObject_CallObject(func_canvas,device);
    // // printf("aaa\n");
    // // PyObject * dtext = PyObject_GetAttrString(draw,"text");
    // // // printf("aaa\n");
    // // PyObject * dbitmap = PyObject_GetAttrString(draw,"bitmap");
    // // printf("aa\n");
    // PyObject *xy = PyTuple_New(2);
    // PyTuple_SET_ITEM(xy,0,Py_BuildValue("i",0));
    // PyTuple_SET_ITEM(xy,1,Py_BuildValue("i",0));
    // PyObject_CallMethod(draw,"text","(O)(s)(s)",xy,"aaa","white");




    // if(!Py_IsInitialized()){
    //     return 1;
    // }
    timer1=clock();
    // printf("aaa\n");
    while(1){
        if(((dt =(clock()-timer1)/1000))>=1000/30){
            printf("%f\n",(float)dt/1000);
            // PyObject_CallMethod(draw,"text","(O)(s)(s)",xy,"aaa","white");
            timer1=clock();
            // while ()
            
        }
    }
    timer1 =clock();
    // while(1){
    //     if(((dt =(clock()-timer1)/1000))>=1000/30){
    //         printf("%f\n",(float)dt/1000);
    //         timer1=clock();
    //     }

    // }
    
    
    return 0;
}